<template>
  <div style="">
    <!-- <span style="color: #409EFF;margin-left: 10px">设置必填项</span> -->
    <el-radio-group v-model="chelaxy" style="margin-left:15px" @change="selectList()">
      <el-radio-button v-if="!(this.$store.getters.hospitalId == 76 || this.$store.getters.hospitalId == 201)" label="胸痛" />
      <el-radio-button label="卒中" />
    </el-radio-group>
    <el-divider />
    <el-row>
      <el-col style="padding: 20px;">
        <el-table
          ref="multipleTable"
          :data="tableData"
          height="700"
          style="width: 100%; margin-top: -30px"
          class="table"
          border
        >
          <el-table-column
            label="位置"
            min-width="150"
            prop="name"
            header-align="center"
            align="center"
          />
          <el-table-column
            prop="describe"
            label="名称"
            min-width="150"
            header-align="center"
            align="center"
          />
          <el-table-column
            label="设置必填项"
            min-width="300"
            header-align="center"
            align="center"
          >
            <template slot-scope="scope">
              <el-radio-group v-model="scope.row.status" @change="changeradio(scope.$index, scope.row)">
                <el-radio :label="1">必填项（有星号）</el-radio>
                <el-radio :label="2">非必填项（无星号）</el-radio>
                <el-radio :label="3">非必填项（有星号）</el-radio>
              </el-radio-group>
            </template>
          </el-table-column>
        </el-table>
        <el-pagination
          style="float: right"
          :current-page="currentPage"
          :page-sizes="[5, 10, 15, 20]"
          :page-size="pagesize"
          layout="total, sizes, prev, pager, next, jumper"
          :total="pageTotal"
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
        />
      </el-col>
    </el-row>
  </div>
</template>
<script>
import { selectList, saveList } from '@/api/back-management/Set_mandeld'
export default {
  name: 'SetMandeld',
  data() {
    return {
      chelaxy: (this.$store.getters.hospitalId == '76' || this.$store.getters.hospitalId == '201') ? '卒中' : '胸痛',
      tableData: [],
      /* 表格分页参数*/
      currentPage: 1,
      pagesize: 10,
      pageTotal: 0,
      userId: this.$store.getters.userId,
      hospitalId: this.$store.getters.hospitalId,
      apiToken: this.$store.getters.apiToken
    }
  },
  created() {
    this.selectList()
  },
  methods: {
    selectList() {
      const data = {
        pageNum: this.currentPage,
        pageSize: this.pagesize,
        apiToken: this.apiToken,
        greenType: this.chelaxy
      }
      selectList(data).then(res => {
        this.tableData = res.data.list
        this.pageTotal = res.data.total
      })
    },
    changeradio(index, row) {
      const obj = {}
      obj.userId = this.userId
      obj.hospitalId = this.hospitalId
      obj.code = row.code
      obj.describe = row.describe
      obj.field = row.field
      obj.id = row.id
      obj.name = row.name
      obj.parentCode = row.parentCode
      obj.sort = row.sort
      obj.state = row.state
      obj.status = row.status
      obj.type = row.type
      obj.url = row.url
      obj.greenType = row.greenType
      console.log(obj)
      saveList(obj).then(res => {
        if (res.code === 9999) {
          this.$message({
            type: 'error',
            message: '修改失败!'
          })
        } else {
          this.$message({
            type: 'success',
            message: '修改成功!'
          })
          this.selectList()
        }
      })
    },
    // 分页尺寸改变
    handleSizeChange(size) {
      this.pagesize = size
    },
    // 分页换页
    handleCurrentChange(currentPage) {
      this.currentPage = currentPage
    }
  }

}
</script>

<style scoped>

</style>
